package com.ceshiren.test.houduankaifa.dao.impl;


import com.ceshiren.test.houduankaifa.dao.StudentMapper;
import com.ceshiren.test.houduankaifa.dto.StudentDto;
import com.ceshiren.test.houduankaifa.util.DataBaseConnectionUtil;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class StudentMapperImpl implements StudentMapper {




    @Override
    public List<StudentDto> findAllStudents() {
        SqlSession sqlSession = DataBaseConnectionUtil.getSqlSession();
        try {
            List<StudentDto> studentDtoList = sqlSession.selectList("student.findAllStudents");
            return studentDtoList;
        }catch (Exception e) {
            throw new RuntimeException(e);
        }finally {
            sqlSession.close();
        }

    }

    @Override
    public Integer addStudents(StudentDto studentDto) {

        SqlSession sqlSession = DataBaseConnectionUtil.getSqlSession();
        sqlSession.insert("student.addStudents", studentDto);


        return 0;
    }

    @Override
    public Integer updateStudents(StudentDto studentDto) {
        return 0;
    }

    @Override
    public Integer delStudents(StudentDto studentDto) {
        return 0;
    }
}
